package cn.hehuoren.quartz.service.impl;

import cn.hehuoren.quartz.dao.QrtzJobRunLogMapper;
import cn.hehuoren.quartz.model.QrtzJobRunLog;
import cn.hehuoren.quartz.service.IQrtzJobRunLogService;
import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import cn.hehuoren.core.utils.GridModel;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class QrtzJobRunLogServiceImpl implements IQrtzJobRunLogService {
    @Resource
	QrtzJobRunLogMapper qrtzJobRunLogMapper;

	@Override
	public int insert(QrtzJobRunLog qrtzJobRunLog) {
		return qrtzJobRunLogMapper.insert(qrtzJobRunLog);
	}

	@Override
	public List<QrtzJobRunLog> select(Integer start, Integer num, String id,
			String jobName, String jobGroup, String runResultCode) {
		return qrtzJobRunLogMapper.select(start, num, id, jobName, jobGroup, runResultCode);
	}

	@Override
	public QrtzJobRunLog getByKey(@Param("id") String id, @Param("jobName") String jobName,
                                  @Param("jobGroup") String jobGroup, @Param("currentDate") String currentDate) {
		return qrtzJobRunLogMapper.getByKey(id,jobName,jobGroup,currentDate);
	}

	@Override
	public int getTotal(String id, String jobName, String jobGroup,
			String runResultCode) {
		return qrtzJobRunLogMapper.getTotal(id, jobName, jobGroup, runResultCode);
	}
	
	
    @Override
	public GridModel<QrtzJobRunLog> selectQuartzJobRunLogPage(QrtzJobRunLog qrtzJobRunLog,
															  int pageNum, int pageSize,
															  String orderStr) {
        PageBounds pageBounds = new PageBounds(pageNum, pageSize, Order.formString(orderStr));
        PageList<QrtzJobRunLog> pageList = (PageList<QrtzJobRunLog>)qrtzJobRunLogMapper.selectQuartzJobRunLogPage(
            qrtzJobRunLog, pageBounds);
        return new GridModel<QrtzJobRunLog>(pageList);
    }
}
